package com.googlecode.pdfbricks.engine.util;

import java.io.File;
import java.io.IOException;

/**
 * @author Johny Huang
 * Utilitis for operating the files.
 */
public final class FileUtils {

	private FileUtils(){
		
	}
	
	public final static void createFile(final String filePath)
			throws IOException {
		if (filePath != null) {
			File file = new File(filePath);
			if(file.exists()){
				throw new IOException("The file has already existed!");
			}
			if (file.isFile()) {
				file.createNewFile();
			}
		}
	}

	public final static void deleteFile(final String filePath) {
		if (isExistFile(filePath)){
			new File(filePath).delete();
		}
	}

	/**
	 * True if the file exists and is a file.
	 * 
	 * @param filePath
	 * @return True if the file exists and is a file. Otherwise,it's false.
	 */
	public final static boolean isExistFile(final String filePath) {
		boolean result = false;
		if (filePath != null) {
			File file = new File(filePath);
			result = file.isFile()&&file.exists();
		}
		return result;
	}
}
